<?php
// +----------------------------------------------------------------------
// | [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Author 荒年 < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 云盟洗车后台
// +----------------------------------------------------------------------
namespace app\yunmeng\controller;

use app\base\controller\Base;
use app\yunmeng\model\YmJiyou as ymjiyouModel;
use think\Db;

class Ymjiyou extends Base
{
  public function lst()
  {
    $model = new ymjiyouModel();
    $jiyou = $model->paginate(20);
    $this->assign('jiyou',$jiyou);
    return view();
  }

  public function addEdit()
  {
    //获取管理员id
    $id = $this->request->has('id') ? $this->request->param('id', 0, 'intval') : 0;
    $model = new ymjiyouModel();
    if($id > 0) {
      //是修改操作
      if($this->request->isPost()) {
        //提交操作
        $post = $this->request->post();
        if(false == $model->allowField(true)->save($post,['id'=>$id])) {
          return $this->error('修改失败');
        } else {
          return $this->success('修改成功','yunmeng/ymjiyou/lst');
        }
      } else {
        //非提交操作
        $info = $model->where('id',$id)->find();
        $this->assign('info',$info);
        return $this->fetch();
      }
    } else {
      //是新增操作
      if($this->request->isPost()) {
        //是提交操作
        $post = $this->request->post();
        if(false == $model->allowField(true)->save($post)) {
          return $this->error('添加失败');
        } else {
          return $this->success('添加成功','yunmeng/ymjiyou/lst');
        }
      } else {
        return $this->fetch();
      }
    }
  }

  public function del($id)
  {
    if($id > 0){
      if(false == Db::name('ym_jiyou')->where('id','=',$id)->delete()){
        $this->error('删除失败');
      } else {
        $this->success('删除成功','yunmeng/ymjiyou/lst');
      }
    } else {
      $this->error('ID不正确');
    }
  }

}

?>